package main

import (
	"com.jtthink/goft_redis/lib"
	"github.com/gin-gonic/gin"
	"log"
)

func main() {

	r := gin.New()
	r.Use(func(context *gin.Context) {
		defer func() {
			if e := recover(); e != nil {
				context.JSON(400, gin.H{"message": e})
			}
		}()
		context.Next()
	})

	r.Handle("GET", "/news/:id", func(ctx *gin.Context) {

		newsID := ctx.Param("id")

		cache := lib.NewCache()
		defer lib.ReleaseNewCache(cache)

		//数据库获取数据
		cache.DBGetter = lib.NewsDBGetter(newsID, cache,"news"+newsID)

		ctx.Header("Content-type", "application/json")
		ctx.String(200, cache.GetCache("news"+newsID).(string))
	})

	err := r.Run(":8080")
	if err != nil {
		log.Println(err)
	}

	//fmt.Println(cache.Get("name"))
	//fmt.Println(cache.Get("name"))
	//fmt.Println(cache.Get("name"))
	//cache.SetCache("name", "活运营")
}
